package work.parabola.keyboardswitch.pojo.query.keyboard;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;
import work.parabola.keyboardswitch.common.PlateConst;
import work.parabola.keyboardswitch.common.ServerResponse;

@Data
@ToString
@EqualsAndHashCode
public class KeyboardListQuery {

    private int pageNum;

    private int pageSize;

    private String searchWord;

    private Integer searchType;

    public ServerResponse validate() {
        if (StringUtils.isBlank(searchWord)) {
            this.searchWord = null;
        } else {
            this.searchWord = "%" + this.searchWord + "%";
        }
        if (this.searchType == null || this.searchType < 1) {
            this.searchType = null;
        } else {
            if (PlateConst.PlateTypeEnum.codeOf(this.searchType) == null) {
                return ServerResponse.createByErrorMessage("键盘类型参数错误");
            }
        }
        return ServerResponse.createBySuccess();
    }
}
